<?php
/**
 * Object Relational Persistence Mapping Class for table: working_calendar_note
 *
 * @package	com.athena
 * @author	LHV
 */
class WorkingCalendarNote extends ORDataObject {

	/**#@+
	 * Fields of table: working_calendar_note mapped to class members
	 */
	var $working_calendar_note_id		= '';
	var $person_id		= '';
	var $date		= '';
	var $note		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'working_calendar_note';

	/**
	 * Primary Key
	 */
	var $_key = 'working_calendar_note_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'WorkingCalendarNote';

	/**
	 * Handle instantiation
	 */
	function WorkingCalendarNote() {
		parent::ORDataObject();
	}

	
	/**#@+
	 * Field: date, time formatting
	 */
	function get_date() {
		return $this->_getDate('date');
	}
	
	function set_date($date) {
		$this->_setDate('date',$date);
	}
	/**#@-*/

	public function getNote($personId, $date) {
		$result = array (
			'id' => 0,
			'note' => ''
		);
		$sql = "SELECT working_calendar_note_id AS id, note FROM $this->_table
				WHERE person_id = $personId AND date = '$date'
				LIMIT 1";
		$res = $this->_execute($sql);
		if (!$res->EOF) {
			$result['id'] = $res->fields['id'];
			$result['note'] = $res->fields['note'];
		}
		return $result;
	}
	
	public function getNoteById($noteId) {
		$sql = "SELECT note FROM $this->_table
				WHERE working_calendar_note_id = $noteId";
		$res = $this->_execute($sql);
		if (!$res->EOF) {
			return $res->fields['note'];
		}
		return '';
	}
	
	public function addNewNote($personId, $date, $note) {
		$data = array (
			'person_id' => $personId,
			'date'		=> $date,
			'note'		=> $note
		);
		$this->populateArray($data);		
		$this->persist();
		return $this->get_id();		
	}
	
	public function updateNewNote($noteId, $note) {		
		$sql = "UPDATE $this->_table SET note = '$note'
				WHERE working_calendar_note_id = $noteId";
		return $this->_execute($sql);
	}
	
	public function deleteNote($noteId) {
		$sql = "DELETE FROM $this->_table WHERE working_calendar_note_id = $noteId";
		return $this->_execute($sql);
	}
}
?>
